layui.use(["table", "laydate", "layer"], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var layDate = layui.laydate;
    var layer = layui.layer;

    function dateModule() {
        layDate.render({
            elem: '#startDate',
            type: 'date',
            format: 'yyyyMMdd',
            trigger: 'click',
            btns: ['clear', 'now']
        });
        layDate.render({
            elem: '#endDate',
            type: 'date',
            format: 'yyyyMMdd',
            trigger: 'click',
            btns: ['clear', 'now']
        });
    }
    dateModule();

    var SmsSendTable = {
        tableId: "smsSendTable",    //表格id
        condition: {
            msisdn: "",
            sendStatus: "",
            smsType: "",
            startDate: "",
            endDate: ""
        }
    };

    SmsSendTable.initColumn = function () {
        return [[
            {field: 'msisdn', align: "center", title: 'MSISDN'},
            {field: 'smsTypeName', align: "center", title: '短信类型'},
            {field: 'sendTime', align: "center", title: '发送时间'},
            {field: 'actionCode', align: "center", title: '动作码'},
            {field: 'params', align: "center", title: '变量参数'},
            {field: 'encodeTypeName', align: "center", title: '编码形式'},
            {field: 'pushStatusName', align: "center", title: '发送状态'}
        ]];
    };

    // 渲染表格
    table.render({
        elem: '#' + SmsSendTable.tableId,
        url: Feng.ctxPath + '/terminalCtrl/smsSend/list',
        height: "full-98",
        cellMinWidth: 100,
        cols: SmsSendTable.initColumn()
    });

    /**
     * 点击查询按钮
     */
    SmsSendTable.search = function () {
        var queryData = {};
        queryData['msisdn'] = $("#msisdn").val();
        queryData['sendStatus'] = $("#sendStatus").val();
        queryData['smsType'] = $("#smsType").val();
        queryData['startDate'] = $("#startDate").val();
        queryData['endDate'] = $("#endDate").val();
        table.reload(SmsSendTable.tableId, {
            where: queryData, page: {curr: 1}
        });
    };
    $("#btnSearch").click(function () {
        SmsSendTable.search();
    });

    /**
     * 发送模板短信
     */
    SmsSendTable.sendTemplate = function () {
        layer.open({
            type: 2,
            title: '发送下行模板短信',
            area: ['580px', '580px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/terminalCtrl/smsSend/toTemplateSmsPage'
        })
    };
    $("#templateSms").click(function () {
        SmsSendTable.sendTemplate();
    });

    /**
     * 发送下行空短信
     */
    SmsSendTable.sendBlank = function () {
        layer.open({
            type: 2,
            title: '发送下行空短信',
            area: ['500px', '320px'],
            skin: 'layui-layer-molv',
            content: Feng.ctxPath + '/terminalCtrl/smsSend/toBlankSmsPage'
        })
    };
    $("#blankSms").click(function () {
        SmsSendTable.sendBlank();
    });
});
